“You can subtype a generic class or interface by extending or implementing it. The relationship between the type parameters of one class or interface and the type parameters of another are determined by the extends and implements clauses.”
http://docs.oracle.com/javase/tutorial/java/generics/inheritance.html
package com.liguoliang.core.dao; import java.util.List; import com.liguoliang.core.modle.Animal; public abstract class AbstractDAO <T extends Animal>{ protected T saveAnimal(T animal) { System.out.println("Save: " + animal.toString()); return animal; } protected abstract List<T> getList(); }
Sub class should follow the contract made by the super class: T extends Animal
Otherwise, got the Error: Bound mismatch: The type ** is not a valid substitute for the bounded parameter
package com.liguoliang.core.dao; import java.util.List; import com.liguoliang.core.modle.Dog; public class DogDAO<WhatEver extends Object> extends AbstractDAO<Dog> { public Dog saveDog(Dog dog) { return saveAnimal(dog); } @Override protected List<Dog> getList() { return null; } public WhatEver whatEver(WhatEver w) { return w; } }
关于Exception的Capture <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.